// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_double_from_decimal64_10_5") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_double_from_decimal64_10_5_0_nullable;"
    sql "create table test_cast_to_double_from_decimal64_10_5_0_nullable(f1 int, f2 decimalv3(10, 5)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_decimal64_10_5_0_nullable values (0, "0.00000"),(1, "0.00000"),(2, "0.00001"),(3, "-0.00001"),(4, "0.00009"),(5, "-0.00009"),(6, "0.09999"),(7, "-0.09999"),(8, "0.90000"),(9, "-0.90000"),(10, "0.90001"),(11, "-0.90001"),(12, "0.99998"),(13, "-0.99998"),(14, "0.99999"),(15, "-0.99999"),(16, "1.00000"),(17, "-1.00000"),(18, "1.00001"),(19, "-1.00001"),
      (20, "1.00009"),(21, "-1.00009"),(22, "1.09999"),(23, "-1.09999"),(24, "1.90000"),(25, "-1.90000"),(26, "1.90001"),(27, "-1.90001"),(28, "1.99998"),(29, "-1.99998"),(30, "1.99999"),(31, "-1.99999"),(32, "9.00000"),(33, "-9.00000"),(34, "9.00001"),(35, "-9.00001"),(36, "9.00009"),(37, "-9.00009"),(38, "9.09999"),(39, "-9.09999"),
      (40, "9.90000"),(41, "-9.90000"),(42, "9.90001"),(43, "-9.90001"),(44, "9.99998"),(45, "-9.99998"),(46, "9.99999"),(47, "-9.99999"),(48, "9999.00000"),(49, "-9999.00000"),(50, "9999.00001"),(51, "-9999.00001"),(52, "9999.00009"),(53, "-9999.00009"),(54, "9999.09999"),(55, "-9999.09999"),(56, "9999.90000"),(57, "-9999.90000"),(58, "9999.90001"),(59, "-9999.90001"),
      (60, "9999.99998"),(61, "-9999.99998"),(62, "9999.99999"),(63, "-9999.99999"),(64, "90000.00000"),(65, "-90000.00000"),(66, "90000.00001"),(67, "-90000.00001"),(68, "90000.00009"),(69, "-90000.00009"),(70, "90000.09999"),(71, "-90000.09999"),(72, "90000.90000"),(73, "-90000.90000"),(74, "90000.90001"),(75, "-90000.90001"),(76, "90000.99998"),(77, "-90000.99998"),(78, "90000.99999"),(79, "-90000.99999"),
      (80, "90001.00000"),(81, "-90001.00000"),(82, "90001.00001"),(83, "-90001.00001"),(84, "90001.00009"),(85, "-90001.00009"),(86, "90001.09999"),(87, "-90001.09999"),(88, "90001.90000"),(89, "-90001.90000"),(90, "90001.90001"),(91, "-90001.90001"),(92, "90001.99998"),(93, "-90001.99998"),(94, "90001.99999"),(95, "-90001.99999"),(96, "99998.00000"),(97, "-99998.00000"),(98, "99998.00001"),(99, "-99998.00001"),
      (100, "99998.00009"),(101, "-99998.00009"),(102, "99998.09999"),(103, "-99998.09999"),(104, "99998.90000"),(105, "-99998.90000"),(106, "99998.90001"),(107, "-99998.90001"),(108, "99998.99998"),(109, "-99998.99998"),(110, "99998.99999"),(111, "-99998.99999"),(112, "99999.00000"),(113, "-99999.00000"),(114, "99999.00001"),(115, "-99999.00001"),(116, "99999.00009"),(117, "-99999.00009"),(118, "99999.09999"),(119, "-99999.09999"),
      (120, "99999.90000"),(121, "-99999.90000"),(122, "99999.90001"),(123, "-99999.90001"),(124, "99999.99998"),(125, "-99999.99998"),(126, "99999.99999"),(127, "-99999.99999")
      ,(128, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_decimal64_10_5_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_decimal64_10_5_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_double_from_decimal64_10_5_0_not_nullable;"
    sql "create table test_cast_to_double_from_decimal64_10_5_0_not_nullable(f1 int, f2 decimalv3(10, 5)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_decimal64_10_5_0_not_nullable values (0, "0.00000"),(1, "0.00000"),(2, "0.00001"),(3, "-0.00001"),(4, "0.00009"),(5, "-0.00009"),(6, "0.09999"),(7, "-0.09999"),(8, "0.90000"),(9, "-0.90000"),(10, "0.90001"),(11, "-0.90001"),(12, "0.99998"),(13, "-0.99998"),(14, "0.99999"),(15, "-0.99999"),(16, "1.00000"),(17, "-1.00000"),(18, "1.00001"),(19, "-1.00001"),
      (20, "1.00009"),(21, "-1.00009"),(22, "1.09999"),(23, "-1.09999"),(24, "1.90000"),(25, "-1.90000"),(26, "1.90001"),(27, "-1.90001"),(28, "1.99998"),(29, "-1.99998"),(30, "1.99999"),(31, "-1.99999"),(32, "9.00000"),(33, "-9.00000"),(34, "9.00001"),(35, "-9.00001"),(36, "9.00009"),(37, "-9.00009"),(38, "9.09999"),(39, "-9.09999"),
      (40, "9.90000"),(41, "-9.90000"),(42, "9.90001"),(43, "-9.90001"),(44, "9.99998"),(45, "-9.99998"),(46, "9.99999"),(47, "-9.99999"),(48, "9999.00000"),(49, "-9999.00000"),(50, "9999.00001"),(51, "-9999.00001"),(52, "9999.00009"),(53, "-9999.00009"),(54, "9999.09999"),(55, "-9999.09999"),(56, "9999.90000"),(57, "-9999.90000"),(58, "9999.90001"),(59, "-9999.90001"),
      (60, "9999.99998"),(61, "-9999.99998"),(62, "9999.99999"),(63, "-9999.99999"),(64, "90000.00000"),(65, "-90000.00000"),(66, "90000.00001"),(67, "-90000.00001"),(68, "90000.00009"),(69, "-90000.00009"),(70, "90000.09999"),(71, "-90000.09999"),(72, "90000.90000"),(73, "-90000.90000"),(74, "90000.90001"),(75, "-90000.90001"),(76, "90000.99998"),(77, "-90000.99998"),(78, "90000.99999"),(79, "-90000.99999"),
      (80, "90001.00000"),(81, "-90001.00000"),(82, "90001.00001"),(83, "-90001.00001"),(84, "90001.00009"),(85, "-90001.00009"),(86, "90001.09999"),(87, "-90001.09999"),(88, "90001.90000"),(89, "-90001.90000"),(90, "90001.90001"),(91, "-90001.90001"),(92, "90001.99998"),(93, "-90001.99998"),(94, "90001.99999"),(95, "-90001.99999"),(96, "99998.00000"),(97, "-99998.00000"),(98, "99998.00001"),(99, "-99998.00001"),
      (100, "99998.00009"),(101, "-99998.00009"),(102, "99998.09999"),(103, "-99998.09999"),(104, "99998.90000"),(105, "-99998.90000"),(106, "99998.90001"),(107, "-99998.90001"),(108, "99998.99998"),(109, "-99998.99998"),(110, "99998.99999"),(111, "-99998.99999"),(112, "99999.00000"),(113, "-99999.00000"),(114, "99999.00001"),(115, "-99999.00001"),(116, "99999.00009"),(117, "-99999.00009"),(118, "99999.09999"),(119, "-99999.09999"),
      (120, "99999.90000"),(121, "-99999.90000"),(122, "99999.90001"),(123, "-99999.90001"),(124, "99999.99998"),(125, "-99999.99998"),(126, "99999.99999"),(127, "-99999.99999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_decimal64_10_5_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_decimal64_10_5_0_not_nullable order by 1;'

}